package spring.framework.aop.framework;

import spring.framework.aop.AdvisedSupport;

/**
 * @author fun.pengzh
 * @class spring.framework.aop.framework.ProxyFactory
 * @desc
 * @since 2021-11-21
 */
public class ProxyFactory {

    private AdvisedSupport adviseSupport;

    public ProxyFactory(AdvisedSupport adviseSupport) {
        this.adviseSupport = adviseSupport;
    }

    public Object getProxy() {
        return createProxy().getProxy();
    }

    private AopProxy createProxy() {
        if (adviseSupport.isProxyTargetClass()) {
            return new Cglib2AopProxy(adviseSupport);
        }
        return new JdkDynamicAopProxy(adviseSupport);
    }

}
